// pages/myreservation/myreservation.js
var api = require("../../utils/api.js")
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        oType: 2,
        page: 1,
        orderlist: {},
        userinfo: {},
        order_status: 2,
    },
    getlist: function() {
        var userinfo = wx.getStorageSync('userInfo');
        if (userinfo.consult) {
            let data = { consult: userinfo.consult.id, page: this.data.page, order_status: this.data.order_status }
            let url = app.globalData.resBaseUrl + app.u.ORDER_CONUSULT_LIST
            api.requestUrl(data, url).then(res => {
                this.setData({
                    orderlist: res.data,
                    userinfo: userinfo
                })
            })
        } else {
            wx.navigateTo({
                url: '../login/login'
            })
        }
    },
    tableCheck: function(e) {
        var that = this;
        that.setData({
            oType: e.currentTarget.dataset.id,
            order_status: e.currentTarget.dataset.id,
            page: 1
        })
        this.getlist();
    },
    /**,
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

    },
    showMore: function() {
        let data = { uid: this.data.userinfo.id, page: this.data.page, order_status: this.data.order_status }
        let url = app.globalData.resBaseUrl + app.u.ORDER_LIST
        api.requestUrl(data, url).then(res => {
            this.setData({
                orderlist: this.data.orderlist.concat(res.data),
            })
        })
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        this.getlist();
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        this.setData({
            page: this.data.page + 1
        })
        this.showMore();
    },

})